/**
 * jims
 */
package com.jims.master.modules.physical.web;

import com.jims.master.common.data.StringData;
import com.jims.master.common.web.BaseController;

import com.jims.master.modules.physical.ResultVo;
import com.jims.master.modules.physical.entity.TInformation;
import com.jims.master.modules.physical.entity.TResultItem;
import com.jims.master.modules.physical.service.TInformationService;
import com.jims.master.modules.physical.service.TResultItemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 总检Controller
 * @author CTQ
 * @version 2017-06-02
 */
@Controller
@RequestMapping(value = "${adminPath}/totalInspection/")
public class TotalInspectionController extends BaseController {

	@Autowired
	private TInformationService informationService;
	@Autowired
	private TResultItemService resultItemService;


	/**
	 * @Title index
	 * @Description 加载总检页面
	 * @param resultItem
	 * @return
	 * @author CTQ
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = "index")
	public String index(TResultItem resultItem, Model model){
		/**1.查询该体检人员是否有未分检项目**/
		/**2.如果没有分检项目，查询所有项目信息展示在页面**/
		resultItem.updateOrgId();
		List<ResultVo> list = resultItemService.findGroupAndItemList(resultItem);
		TInformation information = informationService.findTInfoByPatId(resultItem.getClinicId());
		model.addAttribute("list",list);
		model.addAttribute("resultItem",resultItem);
		model.addAttribute("information",information);
		return "modules/physical/inspection/index";
	}

	/**
	 * @Title save
	 * @Description 总检审核
	 * @param resultVo
	 * @return
	 * @author CTQ
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = "save")
	@ResponseBody
	public StringData save(ResultVo resultVo) {
		StringData data=new StringData();
		int i=resultItemService.saveResultInfo(resultVo);
		if(i>0){
			data.setCode("success");
			data.setData("总检审核成功");
		}else{
			data.setCode("error");
			data.setData("总检审核失败");
		}
		return data;
	}

	/**
	 * @Title cancelAudit
	 * @Description 总检取消审核
	 * @param resultVo
	 * @return
	 * @author CTQ
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = "cancelAudit")
	@ResponseBody
	public StringData cancelAudit(ResultVo resultVo) {
		StringData data=new StringData();
		int i=resultItemService.cancelAudit(resultVo);
		if(i>0){
			data.setCode("success");
			data.setData("总检取消审核成功");
		}else{
			data.setCode("error");
			data.setData("总检取消审核失败");
		}
		return data;
	}

	/**
	 * @Title cancelAudit
	 * @Description 总检打印
	 * @param resultVo
	 * @return
	 * @author CTQ
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = "print")
	@ResponseBody
	public StringData print(ResultVo resultVo) {
		StringData data=new StringData();
		String printPath =resultItemService.print(resultVo);
		data.setCode("success");
		data.setData(printPath);
		return data;
	}
}